/**
 * @author hAmmeRoL, created: 2008-7-15
 * SJTU
 */

package EventHandler;

import protocol.domain.InstantMessage;
import protocol.generic.AbstractProtocolManager;
import protocol.generic.ProtocolEventHandler;
import protocol.domain.UserPresence;

import com.trolltech.qt.QSignalEmitter;

public class JambiEventHandler extends QSignalEmitter implements
		ProtocolEventHandler {

	public Signal1<UserPresence> presenceChanged = new Signal1<UserPresence>();

	public Signal1<InstantMessage> messageArrived = new Signal1<InstantMessage>();
	
	public Signal2<String, AbstractProtocolManager> authenticationPending = new Signal2<String, AbstractProtocolManager>();
	
	public Signal0 entriesAdded=new Signal0();
	
	public Signal0 loggedIn=new Signal0();
	
	public Signal1<UserPresence> getPresenceChangedSignal() {
		return presenceChanged;
	}

	public Signal1<InstantMessage> getMessageArrivedSignal() {
		return messageArrived;
	}
	
	public Signal2<String, AbstractProtocolManager> getAuthenticationPendingSignal() {
		return authenticationPending;
	}
	
	public Signal0 getEntriesAddedSignal() {
		return entriesAdded;
	}
	
	public Signal0 getLoggedInSignal() {
		return loggedIn;
	}

	@Override
	public void messageArrived(InstantMessage message) {
		try {
			thread().sleep(1000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		messageArrived.emit(message);
	}

	@Override
	public void presenceChanged(UserPresence presence) {
		try {
			thread().sleep(1000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		presenceChanged.emit(presence);
	}

	@Override
	public void connectFailed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void loggedIn() {
		loggedIn.emit();
	}

	@Override
	public void loginFailed() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void entriesAdded() {
		entriesAdded.emit();
	}


	@Override
	public void authenticationPending(String clientID,
			AbstractProtocolManager manager) {
		authenticationPending.emit(clientID, manager);
	}

}

